﻿using Hardcodet.Wpf.TaskbarNotification;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace WPF_TEST
{
    /// <summary>
    /// App.xaml 的交互逻辑
    /// </summary>
    public partial class App : Application
    {
        /// <summary>
        /// 托盤
        /// </summary>
        private TaskbarIcon _taskbar;
        protected override void OnStartup(StartupEventArgs e) {
            _taskbar = (TaskbarIcon)FindResource("Taskbar");

            ICommand showMainWindow = new CommandImpl() {
                CommandAction = () => {
                    //顯示主窗口        
                    WPF_TEST.MainWindow.SingleCase.Show();
                    WPF_TEST.MainWindow.SingleCase.WindowState = WindowState.Normal;
                }
            };
            //雙擊托盤圖標事件
            _taskbar.DoubleClickCommand = showMainWindow;
         
            //托盤右鍵菜單
            ContextMenu menu = new ContextMenu();

            //ICommand showWindow = new CommandImpl()
            //{
            //    CommandAction = () => {
            //        //顯示主窗口
            //        //MainWindow _window = new WPF_TEST.MainWindow();
            //        //_window.Show();                
            //        WPF_TEST.MainWindow.SingleCase.Show();
            //    }
            //};

            menu.Items.Add(new MenuItem() { Header = "顯示", Command = showMainWindow });
            ICommand clickMenu = new CommandImpl() {
                CommandAction = () => {
                    //退出程序
                    System.Windows.Application.Current.Shutdown();
                    Environment.Exit(0);
                }
            };
            menu.Items.Add(new MenuItem() { Header="退出",Command= clickMenu });

            _taskbar.ContextMenu = menu;
            ////右鍵托盤圖標事件
            //_taskbar.MouseRightButtonUp += new MouseButtonEventHandler(
            //    (object o,MouseButtonEventArgs me)=> {
            //        _taskbar.ContextMenu.IsOpen = true;
            //});

            base.OnStartup(e);
        }
    }
}
